package org.openmrs.validator;

import org.openmrs.UserObligation;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

public class UserObligationValidator implements Validator {
	
	@SuppressWarnings("unchecked")
	public boolean supports(Class c) {
		return c.equals(UserObligation.class);
	}
	
	@Override
	public void validate(Object obj, Errors errors) {
		UserObligation userObligation = (UserObligation) obj;
		if (userObligation == null) {
			errors.rejectValue("userObligation", "error.general");
		} else {
			ValidationUtils.rejectIfEmptyOrWhitespace(errors, "context", "error.userObligation.context");
			ValidationUtils.rejectIfEmptyOrWhitespace(errors, "value", "error.userObligation.value");
		}
	}
	
}
